<template>
  <div class="container-comlist">
    <template v-for="item in commentList" :key="item.commentNo">
      <div class="item">
        <x-img :src="item.userinfor.img_url" class="comment-img"> </x-img>
        <div class="right">
          <!-- 评论 -->
          <div class="name">{{ item.userinfor.nickname }}</div>
          <div class="content">
            {{ item.content }}
          </div>
          <div class="sendtime">
            {{ formatDate(new Date(item.commentTime),'Y-m-d H:i:s')}}
            <span class="praise hover"
              ><svg-icon class="hover-color" iconName="praise" @click="addLike(item.commentNo)"></svg-icon
              >&nbsp;{{ item.likeNum }}</span
            >
            <!-- <span class="hover-color" @click="handleReplay">回复</span> -->
          </div>
          <!-- 评论回复 -->
          <!-- <div class="repaly-item">
          <lay-avatar
            src="https://portrait.gitee.com/uploads/avatars/user/1611/4835367_Jmysy_1578975358.png"
            class="repaly-img"
          >
          </lay-avatar>
          <div class="repaly-item-right">
            <div class="name">李四 <span class="content">回复 张三：回复内容</span></div>
            <div class="sendtime">
              2023-2-10 10:11:11
              <span class="praise hover"
                ><svg-icon class="hover-color" iconName="praise"></svg-icon>&nbsp;5</span
              >
              <span class="hover-color">回复</span>
            </div>
          </div>
        </div> -->
          <!-- <comment-send style="margin-top: 10px" v-if="showSend"></comment-send> -->
        </div>
      </div>
      <lay-line></lay-line>
    </template>
    <lay-empty v-if="!commentList.length"></lay-empty>
  </div>
</template>

<script setup>
import { ref, defineProps, watch } from 'vue'
import {formatDate} from '@/utils/index'
import * as axiosApi from '@/views/page/api'
const props = defineProps({
  modeNo: String,
  refresh:Boolean
})

const commentList = ref([])

function getList(){
  axiosApi.getCommentList(props.modeNo).then(res => {
    commentList.value = res.data
  })
}

watch(()=>props.refresh,()=>{
  getList()
})

getList()

function addLike(commentNo) {
  axiosApi.addLike(commentNo).then(() => {
    commentList.value.some(item => {
      if (item.commentNo === commentNo) {
        item.likeNum++
        return true
      }
    })
  })
}
// const showSend = ref(false)
// function handleReplay() {
//   showSend.value = true
// }
</script>

<style lang="scss" scoped>
.item {
  display: flex;
  box-sizing: border-box;
  .comment-img {
    width: 50px;
    height: 50px;
    margin-right: 10px;
    overflow: hidden;
  }
  .right {
    flex: 1;
    .repaly-item {
      margin-top: 10px;
      display: flex;
      .repaly-img {
        width: 25px;
        height: 25px;
        margin-right: 10px;
      }
      .repaly-item-right {
        flex: 1;
      }
    }
  }
  .sendtime {
    color: #9499a0;
    font-size: 13px;
    .praise {
      margin: 0 10px;
    }
  }
  .name {
    color: #61666d;
    font-size: 13px;
  }
  .content {
    font-family: PingFang SC, HarmonyOS_Regular, Helvetica Neue, Microsoft YaHei, sans-serif;
    color: #18191c;
    -webkit-font-smoothing: antialiased;
  }
}
</style>
